package com.beamfield.controller.manage.steelplant;

import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.service.serviceimpl.manage.steelplant.SteelplantProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Zephyr
 * @description:
 * @date 2019/7/25
 */
@Controller
@RequestMapping("/cms/steelplant/product")
public class ProductController extends BaseController {

    @Autowired
    private SteelplantProductService steelplantProductService;

    @RequestMapping("/cutting")
    public ModelAndView cutting(){
        return new ModelAndView();
    }

    @RequestMapping("/edit_cutting")
    public ModelAndView editCutting(){
        return new ModelAndView();
    }

    @RequestMapping("/cutting_acceptance")
    public ModelAndView cuttingAcceptance(){
        return new ModelAndView();
    }

    @RequestMapping("/edit_cutting_acceptance")
    public ModelAndView editCuttingAcceptance(){
        return new ModelAndView();
    }

    @RequestMapping("/simple_issue")
    public ModelAndView simpleIssue(){
        return new ModelAndView();
    }

    @RequestMapping("/simple_issue_detail")
    public ModelAndView simpleIssueDetail(){
        return new ModelAndView();
    }

    @RequestMapping("/simple_acceptance")
    public ModelAndView simpleAcceptance(){
        return new ModelAndView();
    }

    @RequestMapping("/edit_simple_issue")
    public ModelAndView editSimpleIssue(){
        return new ModelAndView();
    }

    @RequestMapping("/edit_simple_acceptance")
    public ModelAndView editSimpleAcceptance(){
        return new ModelAndView();
    }

    @RequestMapping("/simple_acceptance_detail")
    public ModelAndView simpleAcceptanceDetail(){
        return new ModelAndView();
    }

    @RequestMapping("/readCuttingData")
    @ResponseBody
    public PageResult readCuttingData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        Long beamId = super.getBeamId(request);
        return steelplantProductService.readCuttingData(offset, limit, beamId);
    }

    @RequestMapping("/doSaveCutting")
    @ResponseBody
    public ApiResult doSavePlan(HttpServletRequest request, String cuttingJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        return steelplantProductService.saveCutting(beamId, userId, cuttingJson);
    }

    @RequestMapping("/deleteCutting")
    @ResponseBody
    public ApiResult deletePlan(HttpServletRequest request){
        String id = request.getParameter("id");
        return steelplantProductService.deleteCutting(id);
    }

    @RequestMapping("/exportCutting")
    public ApiResult exportCutting(HttpServletRequest request, HttpServletResponse response){
        Long beamId = super.getBeamId(request);
        return steelplantProductService.exportCutting(beamId, response);
    }

    @RequestMapping("/readCuttingAcceptanceData")
    @ResponseBody
    public PageResult readCuttingAcceptanceData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        Long beamId = super.getBeamId(request);
        return steelplantProductService.readCuttingAcceptanceData(offset, limit, beamId);
    }

    @RequestMapping("/doSaveCuttingAcceptance")
    @ResponseBody
    public ApiResult doSaveCuttingAcceptance(HttpServletRequest request, String cuttingAcceptanceJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        return steelplantProductService.doSaveCuttingAcceptance(beamId, userId, cuttingAcceptanceJson);
    }

    @RequestMapping("/deleteCuttingAcceptance")
    @ResponseBody
    public ApiResult deleteCuttingAcceptance(HttpServletRequest request){
        String id = request.getParameter("id");
        return steelplantProductService.deleteCuttingAcceptance(id);
    }


    @RequestMapping("/getCuttingByUsepart")
    @ResponseBody
    public ApiResult getCuttingByUsepart(HttpServletRequest request){
        String usepartId = request.getParameter("usepartId");
        return steelplantProductService.getCuttingByUsepart(usepartId);
    }

    @RequestMapping("/readSimpleIssueData")
    @ResponseBody
    public PageResult readSimpleIssueData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        Long beamId = super.getBeamId(request);
        return steelplantProductService.readSimpleIssueData(offset, limit, beamId);
    }

    @RequestMapping("/readSimpleIssueDetailData")
    @ResponseBody
    public PageResult readSimpleIssueDetailData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String issueId = request.getParameter("issueId");
        return steelplantProductService.readSimpleIssueDetailData(offset, limit, issueId);
    }

    @RequestMapping("/doSaveSimpleIssue")
    @ResponseBody
    public ApiResult doSaveSimpleIssue(HttpServletRequest request, String simpleIssueJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        return steelplantProductService.doSaveSimpleIssue(beamId, userId, simpleIssueJson);
    }

    @RequestMapping("/deleteSimpleIssue")
    @ResponseBody
    public ApiResult deleteSimpleIssue(HttpServletRequest request){
        String id = request.getParameter("id");
        return steelplantProductService.deleteSimpleIssue(id);
    }

    @RequestMapping("/readSimpleAcceptanceData")
    @ResponseBody
    public PageResult readSimpleAcceptanceData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        Long beamId = super.getBeamId(request);
        return steelplantProductService.readSimpleAcceptanceData(offset, limit, beamId);
    }

    @RequestMapping("/readSimpleAcceptanceDetailData")
    @ResponseBody
    public PageResult readSimpleAcceptanceDetailData(HttpServletRequest request){
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String acceptanceId = request.getParameter("acceptanceId");
        return steelplantProductService.readSimpleAcceptanceDetailData(offset, limit, acceptanceId);
    }

    @RequestMapping("/doSaveSimpleAcceptance")
    @ResponseBody
    public ApiResult doSaveSimpleAcceptance(HttpServletRequest request, String simpleAcceptanceJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        return steelplantProductService.doSaveSimpleAcceptance(beamId, userId, simpleAcceptanceJson);
    }

    @RequestMapping("/deleteSimpleAcceptance")
    @ResponseBody
    public ApiResult deleteSimpleAcceptance(HttpServletRequest request){
        String id = request.getParameter("id");
        return steelplantProductService.deleteSimpleAcceptance(id);
    }

}
